package socdev.mobile;

import java.util.List;

import socdev.data.Message;
import socdev.data.Project;
import socdev.mobile.MessageAdapter.MessageHolder;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ProjectsAdapter extends ArrayAdapter<Project>{

	Context context;
	int layoutResourceId;
	List<Project> data;
	
	public ProjectsAdapter(Context context, int textViewResourceId, List<Project> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.layoutResourceId = textViewResourceId;
		this.data = objects;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ProjectHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            
            holder = new ProjectHolder();
            holder.name = (TextView)row.findViewById(R.id.name);
            
            row.setTag(holder);
        }
        else
        {
            holder = (ProjectHolder)row.getTag();
        }
        
        Project project = data.get(position);
        holder.name.setText(project.name);
        
        if (project.isMember()) holder.name.setBackgroundColor(Color.GREEN);
        else holder.name.setBackgroundColor(Color.RED);
        return row;
    }
	
	static class ProjectHolder
    {
        TextView name;
    }
}
